import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

username = '18620358128@163.com'
password = 'development73'


def send_mail(text='Email Body翻译邮件', subject='Hello World', from_email=username, to_mails=None, html=None):
    assert isinstance(to_mails, list)

    msg = MIMEMultipart('alternative')
    msg['From'] = from_email
    msg['To'] = ', '.join(to_mails)
    msg['Subject'] = subject
    txt_part = MIMEText(text, 'plain')
    msg.attach(txt_part)
    if html != None:
        html_part = MIMEText("<h1>This is working</h1>", 'html')
        msg.attach(html_part)

    payload = msg.get_payload()

    # login to my smtp server
    server = smtplib.SMTP(host='smtp.163.com', port=25)
    server.ehlo()
    server.starttls()
    server.login(username, password)
    server.sendmail(from_email, to_mails, msg.as_string())
    server.quit()


send_mail(from_email=username, to_mails=[
          '11860083@qq.com', '18620358128@163.com'], html='walker')
